package com.surfilter.risk.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * DateUtil
 * Dis:新增的时间工具类，不知道有没有用处
 * Created by GROM on 2017/2/4.
 */
public class DateUtil {

    private static String DATESTR = "yyyy-MM-dd";
    private static DateFormat dateFormat = new SimpleDateFormat(DATESTR);
    private static Logger logger = LoggerFactory.getLogger(DateUtil.class);

    public static Date string2Date(String str){
        try {
            return dateFormat.parse(str);
        } catch (ParseException e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String date2String(Date date){
        return dateFormat.format(date);
    }

    public static Date getFirstOfMonth(Date currentDate){
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(currentDate);//获取当前日期
        calendar.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
        return calendar.getTime();
    }

    public static Date getLastOfMonth(Date currentDate){
        Calendar calendar=Calendar.getInstance();
        calendar.setTime(currentDate);//获取当前日期
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        return calendar.getTime();
    }

    /***
     * 获取当前年，月
     * @param
     */
    public static  String getYear(){
        return String.valueOf(Calendar.getInstance().get(Calendar.YEAR));
    }
    public static String getMonth(){
        return String.valueOf(Calendar.getInstance().get(Calendar.MONTH)+1);
    }

    public static void  main(String[] args){
//        Date date = new Date();
//        System.out.println(date2String(getLastOfMonth(date)));
//        System.out.println(new Date().getYear() + 1900);
//        System.out.println(new Date().getMonth() + 1);
//        Calendar cal = Calendar.getInstance();
//        int day = cal.get(Calendar.DATE);
//        int month = cal.get(Calendar.MONTH) + 1;
//        int year = cal.get(Calendar.YEAR);
//        int dow = cal.get(Calendar.DAY_OF_WEEK);
//        int dom = cal.get(Calendar.DAY_OF_MONTH);
//        int doy = cal.get(Calendar.DAY_OF_YEAR);
//        System.out.println("Current Date: " + cal.getTime());
//        System.out.println("Day: " + day);
//        System.out.println("Month: " + month);
//        System.out.println("Year: " + year);
//        System.out.println("Day of Week: " + dow);
//        System.out.println("Day of Month: " + dom);
//        System.out.println("Day of Year: " + doy);
    }

}
